package jvm.jtacck.serials;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;

import jvm.jtacck.db.records.ClientSite;
import jvm.jtacck.db.records.Hospital;

/**
 * @author Jesse Jeng
 * 
 *      The Route class wraps a value of the type List<ClientSite>
 *      in an object.
 *      
 *      An object of type Route contains a single field whose type
 *      is List<ClientSite>.
 *      
 */
public class Route implements Serializable {

    /**
     * serialVersionUID for the class
     */
    private static final long serialVersionUID = -3913558679275974161L;

    /**
     * A list of ClientSite objects
     * 
     * See ClientSite
     */
    public final LinkedHashMap<Hospital, List<ClientSite>> route;
    
    /**
     * Constructs a newly allocated Route object that represents the
     * specified list of ClientSite objects
     * 
     * @param clientSiteList
     *      The List<ClientSite> to be contained in an Route.
     */     
    public Route(List<ClientSite> siteRoute) {
        route = new LinkedHashMap<Hospital, List<ClientSite>>();
        for (ClientSite site : siteRoute) {
            Hospital h = site.hospital;
            if (route.containsKey(h)) {
                List<ClientSite> siteList = route.get(h);
                siteList.add(site);
            } else {
                List<ClientSite> siteList = new LinkedList<ClientSite>();
                siteList.add(site);
                route.put(h, siteList);
            }
        }
    }
}
